/*
 * ========================================================
 * Copyright(c) 2014 杭州龙骞科技-版权所有
 * ========================================================
 * 本软件由杭州龙骞科技所有, 未经书面许可, 任何单位和个人不得以
 * 任何形式复制代码的部分或全部, 并以任何形式传播。
 * 公司网址
 * http://www.hzdracom.com/
 * ========================================================
 */
package com.shwread.httpsdk.http.face;

import java.io.File;
import java.util.HashMap;

import logic.constants.Const;

import org.json.JSONObject;

import android.content.Context;

import com.shwread.httpsdk.constant.ResultCode;
import com.shwread.httpsdk.http.base.AbstractHttpURLPostForFile;
import com.shwread.httpsdk.http.callback.ActionListener;
import com.shwread.httpsdk.util.Base64;


/**
 * @Project： Lqyd_Android
 * @Title：UploadUserImageAction
 * @Description：用户上传头像
 * @Author：wayne
 * @Date：2014年8月17日上午11:21:07
 */
public class UploadUserImageAction1
        extends
        AbstractHttpURLPostForFile
{
	private long timeStamp = System.currentTimeMillis();
	String path;
	
	public UploadUserImageAction1(Context context, String path, ActionListener actionListener) {
		super(context, "uploadUserImage.do", actionListener);
		this.context = context;
		this.path = path;
	}
	
	@Override
	public void getParameter(HashMap<String, String> parameter_map) {
		parameter_map.put("account", Const.phone_number);
		parameter_map.put("timeStamp", String.valueOf(timeStamp));
		parameter_map.put("accountType", Const.ACCOUNTTYPE);
		parameter_map.put("clientType", Const.CLIENTTYPE);
		parameter_map.put("cid", Base64.base64Encode(Const.phone_number + Const.ACCOUNTTYPE + Const.CLIENTTYPE + timeStamp, Const.login_key, "UTF-8"));
		
	}
	
	@Override
	protected File getFile() {
		return new File(path);
	}
	
	@Override
	public void doResponseXml(String xml) {
		println(xml);
		int result = -1;
		try
		{
			JSONObject jsonObject = new JSONObject(xml);
			result = jsonObject.getInt("resultCode");
			if (result == 1000)
			{
				listener.OK(jsonObject.getString("returnObject"));
			}
			else
			{
				listener.ERROR(result, ResultCode.getResultText(result));
			}
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
	}
	
	@Override
	protected void doRequestHeader(HashMap<String, String> header_map) {
	}
	
	@Override
	public void dispose() {
	}
	
}
